
extrn   voltbl:byte

;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
; DATA
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
align 4
tintred         dd      ?
tintgreen       dd      ?
tintblue        dd      ?
tintlevel       dd      ?

tinttbl         label   byte
temp=1
rept 40h
                db      3 dup(temp)
  temp=temp+1
endm

;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
; CODE
;±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±

;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
; Do misc stuff, loop and tint switches
; Out:
;   EAX,EBX,ECX,EDX,ESI,EDI,EBP - ?
;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
_misc_setup:
        mov al,'e'
        call _cchekswitchnc
        setnc al
        mov _skipend,al

        mov al,'g'
        call _cchekswitchnc
        jc short misc_setupf3
        mov dword ptr voltbl[0],0a0908004h
        mov dword ptr voltbl[4],0d0c8c0b8h
        mov dword ptr voltbl[8],0e0dcd8d4h
        mov dword ptr voltbl[12],0e8e6e4e2h
misc_setupf3:

        mov al,'l'
        call _cchekswitch
        jnc short misc_setupf0
        mov al,'L'
        call _cchekswitch
        jc short misc_setupf1
misc_setupf0:
        mov edx,_lomembase
        call _ccheksstr
        jc short misc_setupf1
        call misc_setupr0
        jc short misc_setupf1
        mov _loop,eax
misc_setupf1:

        mov al,'t'
        call _cchekswitch
        jnc short misc_setupf2
        mov al,'T'
        call _cchekswitch
        jc _ret
misc_setupf2:
        mov edx,_lomembase
        call _ccheksstr
        jc _ret
        call misc_setupr0
        jc _ret
        cmp eax,63
        ja _ret
        mov tintred,eax
        call misc_setupr0
        jc _ret
        cmp eax,63
        ja _ret
        mov tintgreen,eax
        call misc_setupr0
        jc _ret
        cmp eax,63
        ja _ret
        mov tintblue,eax
        call misc_setupr0
        jc _ret
        cmp eax,63
        ja _ret
        inc eax
        mov esi,64
        sub esi,eax
        mov tintlevel,eax

        mov edi,offset pal00
        mov eax,offset pal0a+64*3*6
        sub eax,edi
        xor edx,edx
        mov ebx,3
        div ebx
        mov ebp,eax
misc_setupl0:
        movzx eax,byte ptr [edi]
        add al,[edi+1]
        add al,[edi+2]
        mov al,tinttbl[eax]
        imul eax,tintlevel
        shr eax,6
        mov ebx,eax
        mov ecx,eax
        mov edx,eax
        imul ebx,tintred
        imul ecx,tintgreen
        imul edx,tintblue

        movzx eax,byte ptr [edi]
        imul eax,esi
        add eax,ebx
        shr eax,6
        stosb
        movzx eax,byte ptr [edi]
        imul eax,esi
        add eax,ecx
        shr eax,6
        stosb
        movzx eax,byte ptr [edi]
        imul eax,esi
        add eax,edx
        shr eax,6
        stosb
        dec ebp
        jnz misc_setupl0

        ret
;-----------------------------------------------------------------------------
misc_setupr0:
        dec edx
        xor ebx,ebx
        xor eax,eax
misc_setupr0l0:
        inc edx
        mov al,[edx]
        cmp al,1
        jc _ret
        sub al,'0'
        jc misc_setupr0l0
        cmp al,9
        ja misc_setupr0l0
misc_setupr0l1:
        inc edx
        mov bl,[edx]
        sub bl,'0'
        jc short misc_setupr0l1d
        cmp bl,9
        ja short misc_setupr0l1d
        cmp eax,429496729
        cmc
        jc _ret
        lea eax,[eax*4+eax]
        lea eax,[eax*2+ebx]
        jmp misc_setupr0l1
misc_setupr0l1d:
        clc
        ret

